package com.gitee.funcy.disruptorlearn.ch03.sigle;

import com.lmax.disruptor.dsl.Disruptor;

import java.util.concurrent.CountDownLatch;

/**
 * @author fangchengyan
 * @date 2019-03-15 18:04
 */
public class TradePublisher implements Runnable {

    private static int PUBLISH_COUNT = 1;

    private CountDownLatch latch;
    private Disruptor<Trade> disruptor;

    public TradePublisher(CountDownLatch latch, Disruptor<Trade> disruptor) {
        this.latch = latch;
        this.disruptor = disruptor;
    }

    @Override
    public void run() {
        TradeEventTranslator eventTranslator = new TradeEventTranslator();
        for(int i = 0; i < PUBLISH_COUNT; i++) {
            // 新的任务提交方式
            disruptor.publishEvent(eventTranslator);
        }
        latch.countDown();
    }
}


